<?php

header("Content-type: application/xhtml+xml");

require_once('../lib/Smarty/Smarty.class.php');
require_once('../lib/HimaShare.php');
require_once('../lib/Schedule.php');
require_once('../lib/Util.php');
require_once('../lib/Constants.php');
require_once('../lib/Config.php');

$data   = make_page(array_merge($_GET, $_POST));
$smarty = new Smarty();
$smarty->assign($data);
$smarty->display($data['error_code'] ? 'error.tmpl' : 'event_invite_by_diary.tmpl');

function make_page ($params) {
    $data = array(
        'error_code' => 0
    );

    if (!validate_signature(array_merge($_GET, $_POST))) {
        $data['error_code'] = 1;
        return $data;
    }

    if (!isset($_GET['date']) || !is_date($_GET['date'])) {
    }

    $user = $_GET['opensocial_owner_id'];
    $date = $_GET['date'];
    $unixstamp = date_to_unix($date);

    $friends = HimaShare::get_friends($user);

    $schedules = array();
    foreach ($friends as $id => $friend) {
        $schedule = Schedule::get_list($id, $date, $date);
        if (!$schedule) continue;
        $schedules = array_merge($schedules, $schedule);
    }

    $data['date']      = $date;
    $data['unixstamp'] = $unixstamp;
    $data['friends']   = $friends;
    $data['schedules'] = $schedules;
    $data['url_prefix'] = URL_PREFIX;

    $data['analytics']    = '<img src="' . googleAnalyticsGetImageUrl() . '" />'; // for google analytics

    return $data;
}

?>
